package com.zlc.workflow.core.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zlc.common.core.process.model.entity.StoneCodeInterface;
import com.zlc.common.core.process.model.vo.StoneCodeInterfaceVo;
import com.zlc.common.core.process.model.vo.StoneInterfaceClassVo;
import com.zlc.common.core.process.model.vo.StoneInterfaceConfigVo;
import com.zlc.common.core.process.service.StoneCodeInterfaceService;
import com.zlc.workflow.core.system.model.InterfaceClassEntity;
import com.zlc.workflow.core.system.service.InterfaceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags = "接口设计配置")
@RestController
@Slf4j
@RequestMapping("/api/system")
public class InterfaceController {

    @Autowired
    private InterfaceService interfaceService;
    @Autowired
    private StoneCodeInterfaceService stoneCodeInterfaceService;

    /**
     * 类别树
     */
    @ApiOperation(value = "类别树")
    @GetMapping(value = "/classTree")
    public InterfaceClassEntity classTree(){
        return interfaceService.classTree();
    }

    /**
     * 添加类别
     */
    @ApiOperation(value = "添加类别")
    @PostMapping(value = "/addClass")
    public void addClass(@RequestBody StoneInterfaceClassVo classVo){
        interfaceService.addClass(classVo);
    }

    /**
     * 保存类别
     */
    @ApiOperation(value = "保存类别")
    @PostMapping(value = "/saveClass")
    public void saveClass(@RequestBody StoneInterfaceClassVo classVo){
        interfaceService.addClass(classVo);
    }

    /**
     * 删除类别
     */
    @ApiOperation(value = "删除类别")
    @GetMapping(value = "/removeClass")
    public void removeClass(@RequestParam(value = "classId") String classId){
        interfaceService.removeClass(classId);
    }

    /**
     * 通过类别ID查询类别下接口信息
     */
    @ApiOperation(value = "通过类别ID查询类别下接口信息")
    @GetMapping(value = "/getInterList")
    public List<StoneInterfaceConfigVo> getInterList(@RequestParam(value = "classId") String classId){
        return interfaceService.getInterList(classId);
    }

    /**
     * 通过类别ID查询类别下接口信息
     */
    @ApiOperation(value = "查询代码接口")
    @GetMapping(value = "/getCodeInterList")
    public List<StoneCodeInterfaceVo> getCodeInterList(){
        LambdaQueryWrapper<StoneCodeInterface> wrapper = new LambdaQueryWrapper<StoneCodeInterface>();
        wrapper.orderByAsc(StoneCodeInterface::getCreateTime);
        return stoneCodeInterfaceService.queryVoList(wrapper);
    }

    /**
     * 添加接口设计
     */
    @ApiOperation(value = "添加接口设计")
    @PostMapping(value = "/addInterfaceConfig")
    public void addInterfaceConfig(@RequestBody StoneInterfaceConfigVo configVo){
        interfaceService.addInterfaceConfig(configVo);
    }

    /**
     * 保存接口设计
     */
    @ApiOperation(value = "保存接口设计")
    @PostMapping(value = "/saveInterfaceConfig")
    public void saveInterfaceConfig(@RequestBody StoneInterfaceConfigVo configVo){
        interfaceService.saveInterfaceConfig(configVo);
    }

    /**
     * 删除接口设计
     */
    @ApiOperation(value = "删除接口设计")
    @GetMapping(value = "/removeInterface")
    public void remove(@RequestParam(value = "id") String id){
        interfaceService.remove(id);
    }
}
